package com.niuxiaofa.newlaw.Activity;

import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Bean.NewInfoBean;
import com.niuxiaofa.newlaw.Bean.NewListBean;
import com.niuxiaofa.newlaw.Bean.SignPageBean;
import com.niuxiaofa.newlaw.Network.ApiService;
import com.niuxiaofa.newlaw.Network.ServiceManager;
import com.niuxiaofa.newlaw.Network.WisdomLibraryPresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.Tools.ToActivityUtil;
import com.niuxiaofa.newlaw.Tools.UIUtils;
import com.niuxiaofa.newlaw.adapter.NewsAdapter;
import com.zzhoujay.richtext.RichText;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


/**
 * 咨询
 */
public class InfomationDetailsActivity extends BaseActivity {

    @BindView(R.id.textview)
    TextView textview;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_infomation_details;
    }

    @Override
    protected void initData() {


        RichText.initCacheDir(getContext());//富文本编辑器

        String id = getIntent().getStringExtra("id");
        Gson gson = new Gson();
        Map map = new HashMap();

        map.put("id", id);
        String json = gson.toJson(map);

        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        Call<NewInfoBean> call = ServiceManager.getInstance().creat(ApiService.class).getNewInfo(body);

        call.enqueue(new Callback<NewInfoBean>() {
            @Override
            public void onResponse(Call<NewInfoBean> call, Response<NewInfoBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    NewInfoBean bean=(NewInfoBean)response.body();
                    RichText.fromHtml(bean.getData().getNewsContent()).into(textview);
                }
            }

            @Override
            public void onFailure(Call<NewInfoBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(), "网络连接异常,请稍候在试", Toast.LENGTH_LONG).show();
            }
        });

    }
}
